package org.example.y25.m3;

import java.util.Scanner;

public class lanqiao_19723 {
    public static void main(String[] args) {
        //操作类型add、sync、query
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = 0;
        }
        String d;
        scanner.nextLine();
        while(scanner.hasNext()){
            d = scanner.nextLine();
            String[] f = d.split(" ");
            switch(f[0]){
                case "add":
                    arr[0]++;
                    break;
                case "sync":
                    arr[Integer.valueOf(f[1])]++;
                    break;
                case "query":
                    int min = Integer.MAX_VALUE;
                    for (int i = 0; i < N; i++) {
                        if(arr[i]== 0){
                            min = 0;
                            break;
                        }else if (arr[i] < min){
                            min = arr[i];
                        }
                    }
                    System.out.println(min);
                    break;
            }

        }
    }
}
